package com.wgb.movie.model.vo;

import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.wgb.movie.model.entity.MovieOrder;
import com.wgb.movie.model.entity.SeatStatus;
import lombok.Data;
import org.springframework.beans.BeanUtils;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * 订单视图
 *
 * @author <a href="https://github.com/liyupi">程序员鱼皮</a>
 * @from <a href="https://www.code-nav.cn">编程导航学习圈</a>
 */
@Data
public class MovieOrderVO implements Serializable {

    /**
     * 订单ID
     */
    private Long id;

    /**
     * 用户ID（购买者）
     */
    private Long userId;

    /**
     * 电影放映场次ID
     */
    private Long movieShowId;

    private String movieName;

    private String theaterName;

    private Integer hallType;

    /**
     * 放映时间
     */
    private Date showTime;

    /**
     * 影院地址
     */
    private String theaterAddress;
    /**
     * 座位信息（JSON格式，例如：["1排", "2座"]
     */
    private SeatStatus seat;

    /**
     * 订单金额
     */
    private BigDecimal price;

    /**
     * 订单状态（例如：0-待支付，1-已支付，2-已取消）
     */
    private Integer orderStatus;

    /**
     * 创建时间
     */
    private Date createTime;

    /**
     * 更新时间
     */
    private Date updateTime;

    /**
     * 创建用户信息
     */
    private UserVO user;

    /**
     * 封装类转对象
     *
     * @param movieOrderVO
     * @return
     */
    public static MovieOrder voToObj(MovieOrderVO movieOrderVO) {
        if (movieOrderVO == null) {
            return null;
        }
        MovieOrder movieOrder = new MovieOrder();
        BeanUtils.copyProperties(movieOrderVO, movieOrder);
        movieOrder.setSeat(JSONUtil.toJsonStr(movieOrderVO.getSeat()));
        return movieOrder;
    }

    /**
     * 对象转封装类
     *
     * @param movieOrder
     * @return
     */
    public static MovieOrderVO objToVo(MovieOrder movieOrder) {
        if (movieOrder == null) {
            return null;
        }
        MovieOrderVO movieOrderVO = new MovieOrderVO();
        BeanUtils.copyProperties(movieOrder, movieOrderVO);
        movieOrderVO.setSeat(JSONUtil.toBean(movieOrder.getSeat(), SeatStatus.class));
        return movieOrderVO;
    }
}
